// The implementation of exslt node-set() function for Saxon-HE processor
// Usage:
//   final TransformerFactory factory = TransformerFactory.newInstance();
//   ((TransformerFactoryImpl) factory).getConfiguration().registerExtensionFunction(new SaxonNodeSet());
//
package by.ad.xml;

import net.sf.saxon.expr.XPathContext;
import net.sf.saxon.lib.ExtensionFunctionCall;
import net.sf.saxon.lib.ExtensionFunctionDefinition;
import net.sf.saxon.om.Item;
import net.sf.saxon.om.SequenceIterator;
import net.sf.saxon.om.StructuredQName;
import net.sf.saxon.trans.XPathException;
import net.sf.saxon.value.SequenceType;

@SuppressWarnings("serial")
public class SaxonNodeSet
  extends ExtensionFunctionDefinition
{
  @Override
  public SequenceType[] getArgumentTypes() { 
    return new SequenceType[] { SequenceType.NODE_SEQUENCE }; 
  }
  
  @Override
  public StructuredQName getFunctionQName() { 
    return new StructuredQName("", "http://exslt.org/common", "node-set"); 
  }
  
  @Override
  public SequenceType getResultType(final SequenceType[] suppliedArgumentTypes) {
    return SequenceType.NODE_SEQUENCE;
  }
  
  @Override
  public boolean trustResultType() { 
    return true;
  }
  
  @Override
  public ExtensionFunctionCall makeCallExpression()
  {
    return new ExtensionFunctionCall() {
      @SuppressWarnings("rawtypes")
      @Override
      public SequenceIterator<? extends Item> call(
        final SequenceIterator<? extends Item>[] arguments, 
        final XPathContext context) throws XPathException 
      {
        return arguments[0];
      }
    };
  }
  
}
